package org.jetnuke.dao.generic;

import org.apache.log4j.Logger;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.jforum.JForumExecutionContext;
import net.jforum.dao.generic.AutoKeys;
import net.jforum.util.preferences.SystemGlobals;

import org.jetnuke.entities.DownloadsDownloads;

public class GenericDownloadDownloadDAO extends AutoKeys implements
		org.jetnuke.dao.DownloadDownloadDAO {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(GenericDownloadDownloadDAO.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#retrieveByPK(int)
	 */
	public DownloadsDownloads retrieveByPK(int id) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("retrieveByPK(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectByID"));
		p.setInt(1, id);

		ResultSet rs = p.executeQuery();
		DownloadsDownloads s = new DownloadsDownloads();

		if (rs.next()) {
			fillDownDownFromResultSet(s, rs);
		}

		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("retrieveByPK(int) - end"); //$NON-NLS-1$
		}
		return s;
	}

	/**
	 * @param s
	 * @param rs
	 */
	protected void fillDownDownFromResultSet(DownloadsDownloads s, ResultSet rs)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger
					.debug("fillDownDownFromResultSet(DownloadsDownloads, ResultSet) - start"); //$NON-NLS-1$
		}

		s.setCID(rs.getInt("CID"));
		s.setDATE(rs.getTimestamp("DATE1"));
		s.setDESCRIPTION(rs.getString("DESCRIPTION"));
		s.setDOWNLOADRATINGSUMMARY(rs.getDouble("DOWNLOADRATINGSUMMARY"));
		s.setEMAIL(rs.getString("EMAIL"));
		s.setFILESIZE(rs.getInt("FILESIZE"));
		s.setHITS(rs.getInt("HITS"));
		s.setHOMEPAGE(rs.getString("HOMEPAGE"));
		s.setLID(rs.getInt("LID"));
		s.setNAME(rs.getString("NAME"));
		s.setSID(rs.getInt("SID"));
		s.setSUBMITTER(rs.getString("SUBMITTER"));
		s.setTITLE(rs.getString("TITLE"));
		s.setTOTALCOMMENTS(rs.getInt("TOTALCOMMENTS"));
		s.setTOTALVOTES(rs.getInt("TOTALVOTES"));
		s.setURL(rs.getString("URL"));
		s.setVERSION(rs.getString("VERSION"));

		if (logger.isDebugEnabled()) {
			logger
					.debug("fillDownDownFromResultSet(DownloadsDownloads, ResultSet) - end"); //$NON-NLS-1$
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectAll()
	 */
	public List selectAll() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectAll() - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		p = JForumExecutionContext.getConnection().prepareStatement(
				SystemGlobals.getSql("DownloadDownloadModel.selectAll"));

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectAll() - end"); //$NON-NLS-1$
		}
		return list;
	}

	protected List processSelectAll(ResultSet rs) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("processSelectAll(ResultSet) - start"); //$NON-NLS-1$
		}

		List list = new ArrayList();
		while (rs.next()) {
			DownloadsDownloads u = new DownloadsDownloads();
			fillDownDownFromResultSet(u, rs);
			list.add(u);
		}

		if (logger.isDebugEnabled()) {
			logger.debug("processSelectAll(ResultSet) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#addNew(org.jetnuke.entities.DownloadsDownloads)
	 */
	public int addNew(DownloadsDownloads dc) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("addNew(DownloadsDownloads) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = this
				.getStatementForAutoKeys("DownloadDownloadModel.addNew");
		this.setAutoGeneratedKeysQuery(SystemGlobals
				.getSql("DownloadDownloadModel.lastGeneratedDownloadID"));
		initNewDownload(dc, p);

		int id = this.executeAutoKeysQuery(p);
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("addNew(DownloadsDownloads) - end"); //$NON-NLS-1$
		}
		return id;
	}

	/**
	 * @param dc
	 * @param p
	 */
	private void initNewDownload(DownloadsDownloads dc, PreparedStatement p)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger
					.debug("initNewDownload(DownloadsDownloads, PreparedStatement) - start"); //$NON-NLS-1$
		}

		p.setInt(1, dc.getCID());
		p.setTimestamp(2, new Timestamp(dc.getDATE().getTime()));
		p.setString(3, dc.getDESCRIPTION());
		p.setDouble(4, dc.getDOWNLOADRATINGSUMMARY());
		p.setString(5, dc.getEMAIL());
		p.setInt(6, dc.getFILESIZE());
		p.setInt(7, dc.getHITS());
		p.setString(8, dc.getHOMEPAGE());

		p.setString(9, dc.getNAME());
		p.setInt(10, dc.getSID());
		p.setString(11, dc.getSUBMITTER());
		p.setString(12, dc.getTITLE());
		p.setInt(13, dc.getTOTALCOMMENTS());
		p.setInt(14, dc.getTOTALVOTES());
		p.setString(15, dc.getURL());
		p.setString(16, dc.getVERSION());

		if (logger.isDebugEnabled()) {
			logger
					.debug("initNewDownload(DownloadsDownloads, PreparedStatement) - end"); //$NON-NLS-1$
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#update(org.jetnuke.entities.DownloadsDownloads)
	 */
	public void update(DownloadsDownloads dc) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("update(DownloadsDownloads) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals.getSql("DownloadDownloadModel.update"));

		p.setInt(1, dc.getCID());
		p.setTimestamp(2, new Timestamp(dc.getDATE().getTime()));
		p.setString(3, dc.getDESCRIPTION());
		p.setDouble(4, dc.getDOWNLOADRATINGSUMMARY());
		p.setString(5, dc.getEMAIL());
		p.setInt(6, dc.getFILESIZE());
		p.setInt(7, dc.getHITS());
		p.setString(8, dc.getHOMEPAGE());

		p.setString(9, dc.getNAME());
		p.setInt(10, dc.getSID());
		p.setString(11, dc.getSUBMITTER());
		p.setString(12, dc.getTITLE());
		p.setInt(13, dc.getTOTALCOMMENTS());
		p.setInt(14, dc.getTOTALVOTES());
		p.setString(15, dc.getURL());
		p.setString(16, dc.getVERSION());

		p.setInt(17, dc.getLID());
		p.executeUpdate();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("update(DownloadsDownloads) - end"); //$NON-NLS-1$
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#countAll()
	 */
	public int countAll() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("countAll() - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals.getSql("DownloadDownloadModel.countAll"));

		ResultSet rs = p.executeQuery();
		rs.next();
		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("countAll() - end"); //$NON-NLS-1$
		}
		return r;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#incHits(int)
	 */
	public void incHits(int id) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("incHits(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals.getSql("DownloadDownloadModel.incHits"));
		p.setInt(1, id);

		p.executeUpdate();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("incHits(int) - end"); //$NON-NLS-1$
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#countUser(int,
	 *      java.lang.String)
	 */
	public int countUser(int lid, String uname) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("countUser(int, String) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		p = JForumExecutionContext.getConnection().prepareStatement(
				SystemGlobals.getSql("DownloadDownloadModel.countUser"));
		p.setInt(1, lid);
		p.setString(2, uname);
		ResultSet rs = p.executeQuery();
		rs.next();

		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("countUser(int, String) - end"); //$NON-NLS-1$
		}
		return r;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#countAllByCategory(int)
	 */
	public int countAllByCategory(int cid) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("countAllByCategory(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		p = JForumExecutionContext.getConnection().prepareStatement(
				SystemGlobals.getSql("DownloadDownloadModel.countByCategory"));
		p.setInt(1, cid);
		ResultSet rs = p.executeQuery();
		rs.next();

		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("countAllByCategory(int) - end"); //$NON-NLS-1$
		}
		return r;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#getByHitsDown(int, int)
	 */
	public List getByHitsDown(int start, int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("getByHitsDown(int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectByHitsDown"));
		p.setInt(1, start);
		p.setInt(2, limit);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("getByHitsDown(int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectDateGreater(java.util.Date)
	 */
	public int selectDateGreater(Date dt) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectDateGreater(Date) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectDateGreater"));
		p.setTimestamp(1, new Timestamp(dt.getTime()));

		ResultSet rs = p.executeQuery();
		rs.next();

		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectDateGreater(Date) - end"); //$NON-NLS-1$
		}
		return r;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#countWithRating()
	 */
	public int countWithRating() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("countWithRating() - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.countWithRating"));

		ResultSet rs = p.executeQuery();
		rs.next();
		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("countWithRating() - end"); //$NON-NLS-1$
		}
		return r;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectWithRating()
	 */
	public List selectWithRating(int totalVotesMin, int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectWithRating(int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectWithRating"));
		p.setInt(1, totalVotesMin);
		p.setInt(2, limit);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectWithRating(int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectTitleAsc(int, int,
	 *      int)
	 */
	public List selectTitleAsc(int cid, int start, int offset) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectTitleAsc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectTitleAsc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectTitleAsc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectTitleDesc(int, int,
	 *      int)
	 */
	public List selectTitleDesc(int cid, int start, int offset)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectTitleDesc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectTitleDesc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectTitleDesc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectDateAsc(int, int, int)
	 */
	public List selectDateAsc(int cid, int start, int rowcount)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectDateAsc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectDateAsc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, rowcount);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectDateAsc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectDateDesc(int, int,
	 *      int)
	 */
	public List selectDateDesc(int cid, int start, int offset) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectDateDesc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectDateDesc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectDateDesc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectRatingAsc(int, int,
	 *      int)
	 */
	public List selectRatingAsc(int cid, int start, int offset)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectRatingAsc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectRatingAsc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectRatingAsc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectRatingDesc(int, int,
	 *      int)
	 */
	public List selectRatingDesc(int cid, int start, int offset)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectRatingDesc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectRatingDesc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectRatingDesc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectHitsAsc(int, int, int)
	 */
	public List selectHitsAsc(int cid, int start, int offset) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectHitsAsc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectHitsAsc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectHitsAsc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectHitsDesc(int, int,
	 *      int)
	 */
	public List selectHitsDesc(int cid, int start, int offset) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectHitsDesc(int, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext
				.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectHitsDesc"));
		p.setInt(1, cid);
		p.setInt(2, start);
		p.setInt(3, offset);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectHitsDesc(int, int, int) - end"); //$NON-NLS-1$
		}
		return list;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#selectTopDown(int)
	 */
	public List selectTopDown(int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectTopDown(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.selectTopDown"));
		p.setInt(1, limit);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectTopDown(int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.model.DownloadDownloadModel#search(java.lang.String,
	 *      java.lang.String)
	 */
	public List search(String title, String description, int start, int rowcount)
			throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("search(String, String, int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals.getSql("DownloadDownloadModel.search"));
		p.setString(1, title);
		p.setString(2, description);
		p.setInt(3, start);
		p.setInt(4, rowcount);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("search(String, String, int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	public void deleteByLID(int lid) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("deleteByLID(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.deleteByLID"));

		p.setInt(1, lid);
		p.executeUpdate();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("deleteByLID(int) - end"); //$NON-NLS-1$
		}
	}

	public int countSearch(String title, String description) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("countSearch(String, String) - start"); //$NON-NLS-1$
		}

		PreparedStatement p = JForumExecutionContext.getConnection()
				.prepareStatement(
						SystemGlobals
								.getSql("DownloadDownloadModel.countSearch"));
		p.setString(1, title);
		p.setString(2, description);
		ResultSet rs = p.executeQuery();
		rs.next();
		int r = rs.getInt(1);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("countSearch(String, String) - end"); //$NON-NLS-1$
		}
		return r;
	}

}
